from django.db import models
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from common.models import MyImageModel, UserOwnedModel

class ProfileImage(MyImageModel, UserOwnedModel):
    isPrimary = models.BooleanField()
	
    class IKOptions:
    # This inner class is where we define the ImageKit options for the model
        spec_module = 'kokoomi.profile.specs'
        cache_dir = 'images'
        image_field = 'image'
        save_count_as = 'num_views'

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    location = models.CharField(max_length=255,blank=True)
    website = models.URLField(blank=True)

def create_profile(sender, **kw):
    user = kw["instance"]
    if kw["created"]:
        profile = UserProfile(user=user)
        profile.save()

post_save.connect(create_profile, sender=User, dispatch_uid="users-profilecreation-signal")